 <template>
     <div class="app-container">
         <div style="text-align: center;margin-bottom: 30px">
             警报设置{{ createStatus ? '新增' : '更新' }}
         </div>
         <el-form :model="configForm" ref="configForm" label-width="100px">
             <el-row :gutter="10">
                 <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                     <el-form-item label="配置名称" prop="name">
                         <el-input type="text" v-model="configForm.name" placeholder="请输入配置名称" clearable></el-input>
                     </el-form-item>
                 </el-col>
                 <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                     <el-form-item label="配置编码" prop="code">
                         <el-input v-model="configForm.code" placeholder="请输入配置编码" clearable></el-input>
                     </el-form-item>
                 </el-col>
                 <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                     <el-form-item label="配置简介描述" prop="remark">
                         <el-input v-model="configForm.remark" placeholder="请输入配置简介描述" clearable></el-input>
                     </el-form-item>
                 </el-col>
                 <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                     <el-form-item label="响应时长" prop="respond">
                         <el-input type="text" v-model="configForm.respond" placeholder="请输入响应时长(s)"
                                   clearable></el-input>
                     </el-form-item>
                 </el-col>
                 <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                     <el-form-item label="通知类型" prop="noticeType">
                         <el-select v-model="configForm.noticeType" placeholder="请选择通知类型" style="width: 100%">
                             <el-option :value="0" label="全体人员 "></el-option>
                             <el-option :value="1" label="部分人员 "></el-option>
                         </el-select>
                     </el-form-item>
                 </el-col>
<!--                 <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">-->
<!--                     <el-form-item label="用户列表" prop="noticeType" v-if="configForm.noticeType==1">-->
<!--                             <el-select v-model="configForm.userIds" multiple placeholder="请选择通知用户" style="width: 100%" >-->
<!--                                 <el-option v-for="(item,index) in userList" :key="index"  :value="item.ucId" :label="item.name"></el-option>-->
<!--                             </el-select>-->
<!--                     </el-form-item>-->
<!--                 </el-col>-->
             </el-row>
         </el-form>
         <div slot="footer" style="text-align: center" class="dialog-footer">
             <el-button @click="cancelConfig">取 消</el-button>
             <el-button :loading="addLoading" v-if="createStatus" type="primary" @click="createConfig">创 建
             </el-button>
             <el-button :loading="addLoading" v-else type="primary" @click="updateConfig">修 改</el-button>
         </div>
     </div>
</template>

<script>
import {getInFireAlarmConfigVo,addInFireAlarmConfig,updateInFireAlarmConfig} from "@/api/fireAlarmConfig";
import {getInUserList} from  "@/api/enterprise"

export default {
    name: "configEdit",
    data() {
        return {
            configForm: {
                userIds:[]
            },
            addLoading: false,
            userList:[],
        }
    },
    computed: {
        createStatus() {
            return this.$route.params.ucId == '0'
        },
    },
    created() {
        this.getInUserList()
        if (!this.createStatus) {
            let ucId = this.$route.params.ucId
            this.getInFireAlarmConfigVo(ucId)
        }
    },
    methods: {
        getInFireAlarmConfigVo(val) {
            getInFireAlarmConfigVo({ucId: val}).then(res => {
                this.configForm = res.data
            }).catch(res => {

            })
        },
        cancelConfig() {
          window.history.back()
        },
        createConfig() {
            this.addLoading = true
            this.$refs['configForm'].validate(valid => {
                if (valid) {
                    addInFireAlarmConfig(this.configForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "添加报警配置成功"
                        })
                        this.cancelConfig()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
        updateConfig() {
            this.addLoading = true
            this.$refs['configForm'].validate(valid => {
                if (valid) {
                    updateInFireAlarmConfig(this.configForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "更新报警配置成功"
                        })
                        this.cancelConfig()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
        getInUserList() {
            getInUserList({deleted: false}).then(res => {
                console.log(res.data)
                this.userList = res.data
            }).catch(error => {

            })
        }
    }

}
</script>
